/**
 * 
 */
package org.jenkon.commons.lang.validator;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Jens Konopka
 * 
 * @param <T>
 *            the type of the validation object
 */
abstract class AbstractConditionValidator<T> implements Validator<T>,
		Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4969668793917749671L;

	private final List<Validator<T>> validators = new ArrayList<Validator<T>>();

	/**
	 * @param validator
	 *            {@link Validator}
	 */
	public void add(final Validator<T> validator) {
		validators.add(validator);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jenkon.commons.validator.Validator#validate(java.lang.Object)
	 */
	@Override
	public final boolean validate(final T value) throws Exception {
		return validate(value, validators);
	}

	/**
	 * @param value
	 * @param validators
	 * @return
	 * @throws Exception
	 */
	protected abstract boolean validate(final T value,
			final List<Validator<T>> validators) throws Exception;

}
